let BaseBean = require('@/common/BaseControl');
let comDriver = require('@/common/driver');

class Bean extends BaseBean{
    constructor(param = {}) {
        super(param);
    }

    vData(id, value){
        if (arguments.length === 2) {
            this.form.vData[this.vKey(id)] = value;
        }
        else {
            return this.form.vData[this.vKey(id)];
        }
    }

    vMethod(id, value){
        if (arguments.length === 2) {
            this.form.vMethod[this.vKey(id)] = value;
        }
        else {
            return this.form.vMethod[this.vKey(id)];
        }
    }

    vComputed(id, value){
        if (arguments.length === 2) {
            this.form.vComputed[this.vKey(id)] = value;
        }
        else {
            return this.form.vComputed[this.vKey(id)];
        }
    }

    vKey(key) {
        return `${this.param.id}_${key}`;
    }

    async build(form) {
        await super.build(form);
        form.param.vMethod[this.vKey('enter')] = (event) => { this.enter();};
    }

    buildData(data){
        data[this.vKey('label')] = this.param.label;

        data[this.vKey('text')] = this.param.text;
        data[this.vKey('value')] = this.param.value;

        data[this.vKey('disabled')] = !this.param.enabled;
        data[this.vKey('visible')] = this.param.visible;
        data[this.vKey('shortkey')] = this.param.shortkey;

    }

    enter(){
        if (this.param.onEnter)
            this.param.onEnter(event);
        else{
            this.form.registCurrentInput();
            this.form.changeNextInput();
        }
    }

    shortKeyClick(){

    }

    buildAfter(form){
        super.buildAfter(form);

    }

    changeVisible() {
        super.changeVisible();
        this.vData('visible', this.param.visible);
    }

    changeEnabled() {
        super.changeEnabled();
        this.vData('disabled', !this.param.enabled);
    }

    beforGetValue(){
        super.beforGetValue();

        this.param.value = this.vData('value');
    }

    valueChanged(){
        super.valueChanged();

        this.vData('value', this.param.value);
    }

    display() {
        super.display();

        this.vData('text', this.param.text);

        return this;
    }

    extract() {
        super.extract();

        this.param.text = this.vData('text');

        return this;
    }

}


module.exports = Bean;
